#ifndef PROTOMASTER_H
#define PROTOMASTER_H
#include <iostream>
//#include <wiringPi.h>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;
void copyOnly(string file, string dest, string address, string password,bool & done)
{
	string s;
	if(dest[0] == '.')
	{
		dest = dest.substr(2, dest.size() - 2);
	}
	s = "sshpass -p "+password+" rcp "+file+" "+address+":"+dest;
	cout<< s << endl;	
	system(s.c_str());
	done = true;
}
int copyDir(string file, string dest, string address, string password)
{
	string s;
	if(dest[0] == '.')
	{
		dest = dest.substr(2, dest.size() - 2);
	}
	s = "sshpass -p "+password+" scp -r "+file+" "+address+":"+dest;
	cout<< s << endl;	
	//system(s.c_str());
	return system(s.c_str());
}
int copyAndCompile(string file, string dest, string address, string password, string ex)
{
	int cond;
	string s, dep, temp;
	ifstream din;
	din.open("./csr-repository/Algorithms/dependencies.txt");
	if(dest[0] == '.')
	{
		dest = dest.substr(2, dest.size() - 2);
	}
	s = "sshpass -p "+password+" rcp "+file+" "+address+":"+dest;
	//cout<< s << endl;
	cond = system(s.c_str());
	if(cond == 0)
	{
		if(!din.fail())
		{
			while(!din.eof())
			{
				getline(din, temp);
				dep += temp;
			}
			din.close();
		}
		s = "sshpass -p "+password+" rsh "+address+" g++ -o "+ex+" "+dest+" "+dep;
		return cond + system(s.c_str());
	}
	else
	{
		return cond;
	}
}


void rcmd(string address, string password, string com, bool & done)
{
	string dest, s;
	s = "sshpass -p "+password+" rsh "+address+" "+com;
	cout << s;
	system(s.c_str());
	done = true;
}
 

#endif
